package com.lyb;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

// 发送方
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringBootRabbitMQDemo.class)
public class Send {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void testSend(){
        String message = "朝时有酒、朝时醉，拖至暮时、或变味。";
        for (int i = 0 ; i < 20 ; i++) {
            if (i % 2 == 0) {
                rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM,"email.xxx",message);
            } else {
                rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM,"sms.xxx",message);
            }
        }
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

